//
//  TextViewController.m
//  IQKeyboardManager
//
//  Created by chenleping on 2018/11/21.
//  Copyright © 2018年 梁森. All rights reserved.
//

#import "TextViewController.h"

#import "TableViewViewController.h"
#define kIQCGPointInvalid CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX)
@interface TextViewController ()

@end

@implementation TextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
    
    UIButton * redBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:redBtn];
    redBtn.backgroundColor = [UIColor redColor];
    redBtn.frame = CGRectMake(0, 200, 50, 50);
    [redBtn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    [redBtn setTitle:@"返回" forState:UIControlStateNormal];
    [redBtn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    
    CGPoint point = kIQCGPointInvalid;
    NSLog(@"point:===%@", NSStringFromCGPoint(point));
    
    UIButton * yellowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:yellowBtn];
    yellowBtn.backgroundColor = [UIColor yellowColor];
    yellowBtn.frame = CGRectMake(100, 200, 100, 50);
    [yellowBtn setTitle:@"恢复..." forState:UIControlStateNormal];
    [yellowBtn addTarget:self action:@selector(restoreAction) forControlEvents:UIControlEventTouchUpInside];
    [yellowBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    
    UITextField * contentField = [UITextField new];
    [self.view addSubview:contentField];
    contentField.backgroundColor = [UIColor yellowColor];
    contentField.placeholder = @"输入内容...";
    contentField.frame = CGRectMake(0, 280, 100, 30);
    UIView * inputAccessoryView = [UIView new];
    inputAccessoryView.frame = CGRectMake(0, 0, self.view.frame.size.width, 80);
    inputAccessoryView.backgroundColor = [UIColor redColor];
    [contentField setInputAccessoryView:inputAccessoryView];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
    tap.numberOfTapsRequired = 1;
    [inputAccessoryView addGestureRecognizer:tap];
    
    UIButton * tableViewBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:tableViewBtn];
    tableViewBtn.backgroundColor = [UIColor yellowColor];
    tableViewBtn.frame = CGRectMake(0, 320, 100, 30);
    [tableViewBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [tableViewBtn setTitle:@"Tableview..." forState:UIControlStateNormal];
    [tableViewBtn addTarget:self action:@selector(testTableView) forControlEvents:UIControlEventTouchUpInside];
}
- (void)dismiss{
    [self.view endEditing:YES];
}
- (void)testTableView{
    TableViewViewController * tableViewC = [TableViewViewController new];
    [self presentViewController:tableViewC animated:YES completion:nil];
}
- (void)clickBtn{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    CGPoint origin = self.view.frame.origin;
    origin = CGPointMake(0, -100);
    CGRect frame = self.view.frame;
    frame.origin = origin;
    self.view.frame = frame;
}
- (void)restoreAction{
    CGPoint origin = CGPointMake(0, 0);
    CGRect frame = self.view.frame;
    frame.origin = origin;
    self.view.frame = frame;
}
@end
